from fastapi import FastAPI
import uvicorn
from granian import Granian

from core.init_app import create_app, lifespan
from config.base import get_settings

settings = get_settings()

app = create_app(lifespan=lifespan)

if __name__ == "__main__":
    # uvicorn.run(
    #     app="main:app", 
    #     host=settings.server.HOST, 
    #     port=settings.server.PORT, 
    #     reload=settings.server.RELOAD, 
    #     workers=settings.server.WORKERS
    # )
    
    # 使用 granian
    server = Granian(
        target="main:app",
        interface="asgi",
        address=settings.server.HOST,
        port=settings.server.PORT,
        workers=settings.server.WORKERS,
        runtime_threads=settings.server.THREADS,
        url_path_prefix=settings.server.PREFIX,
        reload=settings.server.RELOAD,
        log_level="info"
    )
    server.serve()
    